{ Russian Olympiad. 1 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/roi/stage1/roi_1stage.doc
  Problem 2
  Points: 20
}
var i,j,n:integer; res,key:array[1..30001] of int64;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do res[i]:=0;
read(key[1]);
res[1]:=0;
for I := 2 to n do begin
  read(key[i]);
  if i=2 then res[2]:=abs(key[2]-key[1]) else begin
    if (res[i-2]+3*(abs(key[i]-key[i-2])))<(res[i-1]+abs(key[i]-key[i-1])) then res[i]:=(res[i-2]+3*(abs(key[i]-key[i-2]))) else res[i]:=(res[i-1]+abs(key[i]-key[i-1]));
  end;
end;
writeln(res[n]);
close(input);
close(output);
end.